import personalForOnewayDistHtml from 'ngtemplate!html!../../../tpls/realtime/personal.oneway.dist.tpl.html';
import personalForCircleDistHtml from 'ngtemplate!html!../../../tpls/realtime/personal.circle.dist.tpl.html';
import validHtml from 'ngtemplate!html!../../../tpls/dialog/valid.dialog.html';

class RealtimeListPersonalController {
    constructor($rootScope, $scope, $cookieStore, $timeout, $state, $filter, ngDialog, tableService, dialogService, ScoreService, getRaceDetail, getCourseList, iRunner, getGroupList){

        var vm = this;

        vm.$rootScope    = $rootScope;
        vm.$cookieStore  = $cookieStore;
        vm.$timeout      = $timeout;
        vm.$state        = $state;
        vm.$filter       = $filter;
        vm.ngDialog      = ngDialog;
        vm.tableService  = tableService;
        vm.dialogService = dialogService;
        vm.ScoreService  = ScoreService;
        vm.iRunner       = iRunner;


        //赛事详情
        vm.raceDetail = getRaceDetail;

        //科目列表详情
        vm.courseList = getCourseList.data;

        // 科目不为空, 默认选中第一个
        if (vm.courseList.length>0) {
            vm.course = vm.courseList[0];
        }
        //保存当前科目名称
        vm.crouseState = {};
        //保存当前页面数据
        vm.realtimeData = [];

        //搜索后的过滤状态（courseType, courseId, sex, cpCircleNum, group, state, bib）
        vm.searchState = {
            race_name: vm.raceDetail.data.disp_name,
            course_name: '',
            type: '',
            courseId: '',
            sex: '',
            cpCircleNum: '',
            group: '',
            state: '', 
            bib: '',
            pageNums: '50',
            page: '1', 
            realtimeData: []
        }


        //获取组别列表
        vm.groupList = getGroupList;

        console.log(getGroupList);

        //分组结构
        vm.groupTypeList = [
            // {
            //     gulpName: group.group_name,
            //     gulpTitleList: [ {
            //         gulpTitle: '',
            //         gulpId
            //     } ]
            // }
        ];
        //循环组别列表
        angular.forEach(getGroupList.data, function (group) {
            var groupTitleSaveFlag = false;
            angular.forEach(vm.groupTypeList, function(groupType) {
               if (group.group_name == groupType.gulpName) {
                // alert(group.group_name);
                // alert(groupType.gulpName);
                    groupType.gulpTitleList.push({
                            gulpTitle: group.group_title,
                            gulpId: group.group_id
                        });
                    groupTitleSaveFlag = true;
               }
            });

            if (!groupTitleSaveFlag) {
                vm.groupTypeList.push(
                    {
                        gulpName: group.group_name,
                        gulpTitleList: [{
                            gulpTitle: group.group_title,
                            gulpId: group.group_id
                        }]
                    }
                )
            }
            
        });

        vm.gulpSelect = [
            // {
            //     title: 'gulp_1',
            //     value: '1',
            //     disabled: 'true'
            // }
        ];
        angular.forEach(vm.groupTypeList, function (element) {

            vm.gulpSelect.push({
                title: element.gulpName,
                value: element.gulpName,
                disabled: 'true'
            });

            angular.forEach(element.gulpTitleList, function (element2) {
                vm.gulpSelect.push({
                    title: '　' + element2.gulpTitle,
                    value: element2.gulpId,
                    disabled: ''
                });
            })
        });



        /**
         * 监听科目变化
         * @param  {[type]} angular.bind(vm, ()            [description]
         * @param  {[type]} (newValue,       oldValue      [description]
         * @return {[type]}                  [description]
         */
        $scope.$watch(angular.bind(vm, () => vm.course), (newValue, oldValue) => {
            //获取当前科目的小组
            // vm.groupListForcourse = [];
            // angular.forEach(vm.groupList.data, (value, index) => {
            //     if (newValue.course_id == value.course_id) {
            //         vm.groupListForcourse.push(value);
            //     }
            // });
            
            //保存当前科目名称
            vm.crouseState = newValue;

            //清空过滤条件
            vm.sex = '';
            vm.cpcircleNum = '';
            vm.group = '';
            vm.state = '';
            vm.bib = '';

            console.log(newValue);
            // 查看是否从详情页面跳转
            if (vm.$rootScope.realltimepersonalback == 1) {
                vm.$rootScope.realltimepersonalback == 0;

                //选择科目
                angular.forEach(vm.courseList, function(data,index){
                    if (data.course_id == vm.$rootScope.searchState.courseId) {
                        vm.course = vm.courseList[index];
                        return;
                    }
                });

                //填充搜索条件
                vm.sex = vm.$rootScope.searchState.sex;
                vm.cpcircleNum = vm.$rootScope.searchState.cpCircleNum;
                vm.group = vm.$rootScope.searchState.group;
                vm.bib = vm.$rootScope.searchState.bib;

                //搜索数据
                //(courseType, courseId, sex, cpCircleNum, group, state, bib)
                vm.searchTableData(vm.$rootScope.searchState.type, vm.$rootScope.searchState.courseId, vm.$rootScope.searchState.sex, vm.$rootScope.searchState.cpCircleNum, vm.$rootScope.searchState.group, vm.$rootScope.searchState.state, vm.$rootScope.searchState.bib);
            } else {
                //搜索数据
                vm.searchTableData(newValue.course_type, vm.course.course_id, '', '', '', '', '');
            }
        });


        //大屏幕直播（上海交大）&& 跑动金融圈
        if (vm.$state.params.race_id == '272' || vm.$state.params.race_id == '273' || vm.$state.params.race_id == '472' || vm.$state.params.race_id == '487') {
            vm.screenLiveDisplay = true;
        } else {
            vm.screenLiveDisplay = false;
        }
        /**
         * 大屏幕直播
         */
        vm.screenLive = function() {
            localStorage.setItem('tokenForScreenLive', vm.$cookieStore.get('access_token'));
            var start_time =  vm.raceDetail.data.start_time;
            var end_time =  vm.raceDetail.data.end_time;
            var start = new Date(Date.UTC(start_time.substring(0, 4), parseInt(start_time.substring(5, 7)) - 1, start_time.substring(8, 10), start_time.substring(11, 13), start_time.substring(14, 16), start_time.substring(17, 19))).getTime()/1000 - 28800;
            var end = new Date(Date.UTC(end_time.substring(0, 4), parseInt(end_time.substring(5, 7)) - 1, end_time.substring(8, 10), end_time.substring(11, 13), end_time.substring(14, 16), end_time.substring(17, 19))).getTime()/1000 - 28800;

            //打开打印页面（跑动金融圈）
            window.open("/pdjrq-shanghai.html?token=" + vm.$cookieStore.get('access_token') + '&race_id='+ vm.$state.params.race_id +'&start=' + start + '&end=' + end + '&male_course_id=704&female_course_id=704&team_course_id=704');
        }
        
        /**
         * 检查是否作弊
         * @return {[type]} [description]
         */
        vm.check = function() {
                //初始数据准备
                $.ajax({
                    dataType:'json',
                    type: 'GET',
                    url: "/dashboard/realtime/check?race_id=" + vm.course.race_id + "&access-token=" + this.$cookieStore.get('access_token'),
                    success: function(data) {
//                        console.log(data);
                        //请求成功的场合
                        if (data.code == 0) {
                            //表格数据
                            vm.searchState.checkData= data.data,
                            //存储数据到Local storage
                            localStorage.setItem('checkDataForPrint', JSON.stringify(vm.searchState));
//                            console.log(vm.searchState);
                        	window.open("tpls/realtime/printforcheck.html");
                        } else {
                            vm.dialogService.error('信息请求失败1');
                        }
                    },
                    error: function(error) {
                        vm.dialogService.error('信息请求失败2');
                    }
                });
        }


        /**
         * 发布成绩
         */
        vm.publish = function() {

            // 模态框显示文本
            $rootScope.common = {
                text : '是否发布成绩'
            }

            vm.ngDialog.open({
                template: validHtml,
                className: 'ngdialog-theme-default ngdialog-alert',
                scope: $scope
            });


            $rootScope.submitDelForm = (isValid) => {
                if (!isValid) {
                    vm.dialogService.error();
                }

                if (isValid) {

                    // 关闭模态框
                    vm.ngDialog.close();
                    // 显示进度条
                    $rootScope.progressBar = true;


                    var status = '', start = '', total = '';
                    // 完结时间
                    var dueTime = '--';

                    // 重新计算所有成绩（调用后台接口）
                    var importStart = (status, start, total) => {
                        vm.ScoreService.getRealtimeScorePublish(vm.$cookieStore.get('access_token'), vm.$state.params.race_id + '&start=' + start)
                        .then( data => {
                            console.log(data);
                            if (data.code == 0) {

                                status = data.data.status;
                                start = data.data.current;
                                total = data.data.total;

                                //设置进度条百分比
                                $rootScope.progress =  parseInt(start/total*100) + '%';
                                //总条数
                                $rootScope.total = total;
                                //完结条数
                                $rootScope.begin = start;
                                // 完结时间（耗时）
                                $rootScope.dueTime = parseInt((total-start)/4) + '秒';


                                if (status == 'continue') {
                                    importStart(status, start, total);                        
                                } else if (status == 'done') {
                                    $rootScope.progressBar = false;
                                    return;
                                }

                            } else {
                                vm.dialogService.error(data.message);
                            }

                        }, error => {
                            vm.dialogService.error("计算失败");
                            console.log('error')
                        });
                    }

                    importStart(status, start, total);

                }
                console.log('重新计算所有成绩')
                return false;
            }
        }

        /**
         * 重新计算所有成绩
         * @return {[type]} [description]
         */
        vm.recalc = function() {

            // 模态框显示文本
            $rootScope.common = {
                text : '您要重新计算所有选手的成绩吗？这将耗费数分钟或更长时间'
            }

            vm.ngDialog.open({
                template: validHtml,
                className: 'ngdialog-theme-default ngdialog-alert',
                scope: $scope
            });

 

            $rootScope.submitDelForm = (isValid) => {
                if (!isValid) {
                    vm.dialogService.error();
                }

                if (isValid) {

                    // 关闭模态框
                    vm.ngDialog.close();
                    // 显示进度条
                    $rootScope.progressBar = true;


                    var status = '', start = '', total = '';
                    // 完结时间
                    var dueTime = '--';

                    // 重新计算所有成绩（调用后台接口）
                    var importStart = (status, start, total) => {
                        vm.ScoreService.getRealtimeScorecalc(vm.$cookieStore.get('access_token'), vm.$state.params.race_id + '&start=' + start)
                        .then( data => {
                            console.log(data);
                            if (data.code == 0) {

                                status = data.data.status;
                                start = data.data.current;
                                total = data.data.total;

                                //设置进度条百分比
                                $rootScope.progress =  parseInt(start/total*100) + '%';
                                //总条数
                                $rootScope.total = total;
                                //完结条数
                                $rootScope.begin = start;
                                // 完结时间（耗时）
                                $rootScope.dueTime = parseInt((total-start)/4) + '秒';


                                if (status == 'continue') {
                                    importStart(status, start, total);
                                } else if (status == 'done') {
                                    $rootScope.progressBar = false;
                                    return;
                                }

                            } else {
                                vm.dialogService.error(data.message);
                            }

                        }, error => {
                            vm.dialogService.error("计算失败");
                            console.log('error')
                        });
                    }

                    importStart(status, start, total);

                }
                console.log('重新计算所有成绩')
                return false;
            }
            
        }


        /**
         * 打印实时页面成绩
         * @return {[type]} [description]
         */
        vm.print = function() {

            //科目名称
            vm.searchState.course_name = vm.crouseState.course_name,
            //科目赛制
            vm.searchState.type = vm.crouseState.course_type,
            //表格数据
            vm.searchState.realtimeData = vm.realtimeData,

            //存储数据到Local storage
            localStorage.setItem('realtimeDataForPrint', JSON.stringify(vm.searchState));
            console.log(vm.searchState);
            //打开打印页面
            window.open("tpls/realtime/printforpersonal.html");
        }

        /**
         * 下载成绩
         * @return {[type]} [description]
         */
        vm.download = function() {
            //下载成绩链接
            vm.window = window.open("/dashboard/realtime/download?course_id=" + vm.course.course_id + "&access-token=" + this.$cookieStore.get('access_token'));                 
        }

        /**
         * [searchTableData description]
         * @return {[type]} [description]
         */
        vm.searchTableData = function (courseType, courseId, sex, cpCircleNum, group, state, bib) {

            // 保存赛制
            vm.searchState.type = courseType;
            //科目id  
            vm.searchState.courseId = courseId;
            //保存搜索性别状态
            vm.searchState.sex = sex;
            //保存cp点或者圈数
            vm.searchState.cpCircleNum = cpCircleNum;
            //保存组别信息
            vm.searchState.group = group;
            //状态信息
            vm.searchState.state = state;
            //选手号信息
            vm.searchState.bib = bib;

            //清空模板数据
            vm.$timeout( () => { vm.personalTpl = ''; }, 0);

            // 单程定距的场合(自定义)
            if (courseType == 'oneway' || courseType == 'custom') {

                //个人实时成绩单程定距模板
                vm.$timeout( () => { vm.personalTpl = personalForOnewayDistHtml; }, 0);
                //请求数据（个人实时成绩单程定距）
                vm.$timeout( () => { vm.getOnewayDistData(courseId, sex, cpCircleNum, group, state, bib); }, 0);   
            } else if (courseType == 'circle') {

                // 个人实时成绩单程定距模板
                vm.$timeout( () => { vm.personalTpl = personalForCircleDistHtml; }, 0);
                //请求数据（个人实时成绩绕圈定距）
                vm.$timeout( () => { vm.getCircleDistData(courseId, sex, cpCircleNum, group, state, bib); }, 0);   

            } else {
                vm.dialogService.error("该赛制本页面未提供查询功能，跳转到实时页面查询。");
                vm.$timeout( () => { vm.ngDialog.close();vm.$state.go('dashboard.race.realtimelist'); }, 2000);
            }

        }

        /**
         * [getCircleDistData 个人实时成绩（绕圈定距）]
         * @param  {[type]} courseId  [科目]
         * @param  {[type]} sex       [性别]
         * @param  {[type]} circleNum [圈数]
         * @param  {[type]} group     [组别]
         * @param  {[type]} state     [状态]
         * @param  {[type]} bib       [选手号]
         * @return {[type]}           [个人实时成绩（绕圈定距）]
         */
        vm.getCircleDistData = function(courseId, sex, circleNum, group, state, bib) {

            var course_id = this.course.course_id,
                sex  = sex || '',
                circleNum = circleNum || '',
                group = group || '',
                state = state || '',
                bib = bib || '',
                search    = this.$state.params.race_id + '&course_id=' + courseId + '&search[sex]=' + sex + '&search[nums]=' + circleNum + '&search[group]=' + group + '&search[state]=' + state + '&search[bib]=' + bib + '&access-token=' + this.$cookieStore.get('access_token');

            var URL = iRunner.config.baseUrl;
            //模板id
            var tplId = '#person_table_circle_dist';

            //用于存储页面上的所有选手id用于查询漏电选手
            var runnerIdList = '';

            vm.realtimeData = [];

            var tableData = angular.element(tplId).DataTable($.extend({}, vm.tableSettings.dataTable, {
                // --- Data
                ajax: URL + '/realtime/personal?race_id=' + search,
                order: [0, "desc"], // ID 倒序
                // --- Column       
                columns: iRunner.personCircleDistColumns,
                // --- CreatedRow
                createdRow: ( row, data, index ) => {
                    //如果有bib号搜索或者圈数为全部的情况下 无排名
                    if (bib) {
                        row.children[6].innerHTML = '-';
                        // 排名隐藏（打印）
                        data.seq = '-';
                    }

                    //保存当前页面数据
                    vm.realtimeData.push(data);

                    // console.log(row);
                    runnerIdList += ',' + data.runner_id;
                },
                // --- Callback
                initComplete: () => {
                    //添加漏点提示
                    // vm.leak();
                }
            }));

            // 点击选手号（跳转选手详情页面）
            $(tplId).on('click', 'tbody > tr a', function() {

                //存储当前搜索条件
                vm.$rootScope.searchState = vm.searchState;

                var params = {
                    action: 'realtime',
                    name: 'dashboard.race.realtimerunner',
                    id: 'runner_id'
                }

                if (!params) return;
                console.log(params);

                var data = {},
                    that = $(this),
                    link = $(this);
                if (!link.data('runnerid')) return;
                if (link.data('course')) {
                    data['course_id'] = link.data('course')
                }    
                if (link.data('runnerid')) {    
                    data[params.id] = link.data('runnerid');
                    vm.$state.go(params.name, data);
                }
            });


            // 上下每页条数下拉框同步
            $('.dataTables_length').find('select').on('change', function(event) {
                //清空当前页面数据
                vm.realtimeData = [];
                const select =  $('.dataTables_length').find('select');
                //保存页面每页显示条数
                vm.searchState.pageNums = $(this).val();

                select.val($(this).val())
            });


            //重绘表格后执行
            $(tplId).on( 'draw.dt', function () {
                //添加漏点提示
                vm.leak();
            });

            //单程绕圈调漏点查询
            vm.leak = function() {
                if (vm.realtimeData.length > 0) {
                    //初始数据准备
                    $.ajax({
                        dataType:'json',
                        type: 'GET',
                        //http://local.timing.paobuqu.com/dashboard/realtime/leak?runner_ids=233404&course_id=241&access-token=
                        url: '/dashboard/realtime/leak?course_id=' + vm.course.course_id + '&runner_ids=' + runnerIdList.substring(1) + '&access-token=' + vm.$cookieStore.get('access_token'),
                        success: function(data) {
                            console.log(data);
                            //请求成功的场合
                            if (data.code == 0) {
                                $('tbody tr').each(function(index,element) {
                                    element.childNodes[7].innerHTML = data.data[$(element.childNodes[0].childNodes[0]).data('runnerid')] == 1 ? "<span style='color: #525252;'>漏点</span>" : '';
                                    console.log($(element.childNodes[0]).data('runnerid'));
                                });
                            } else {
                                vm.dialogService.error('漏点信息请求失败');
                            }
                        },
                        error: function(error) {
                            vm.dialogService.error('漏点信息请求失败');
                        }
                    });
                }
            }
            
            //换页点击
            $('.dataTables_paginate').on('click', "ul > li", function() {
                // alert('23234');
                console.log('this.val()');
                // vm.searchState.page = $(this).val();
                //清空当前页面数据
                vm.realtimeData = [];
            });


            //点击置无效按钮
            $(tplId).on('click', "tbody > tr [data-action='realtime_list']", function() {
                vm.ngDialog.open({
                    template: "<p>确定要将" + $(this).data('bib') +"选手置为无效吗？<br> 点击确定按钮后，该选手所有成绩无效，实时成绩列表中不再显示该选手！</p><br><button class='btn btn-primary' ng-click='setDNF(" + $(this).data('scoreid') + ")'>确定</button>",
                    className: 'ngdialog-theme-default ngdialog-alert',
                    plain: true,
                    scope: $rootScope
                });

            });

            //置选手无效按钮点击确认
            $rootScope.setDNF = function(value) {

                //调用接口，置选手无效
                vm.ScoreService.getRealtimeupdateScore(vm.$cookieStore.get('access_token'), value + '&op=dnf')
                .then( data => {
                    // 成功调用
                    data.code==0&&vm.dialogService.success('调用成功');
                    // 调用失败, 提示用户
                    data.code!=0&&vm.dialogService.error(data.message);
                    console.log(data)
                }, error => console.log('error'));                    

                //关闭确认充值模态框
                vm.ngDialog.close();
                // 重新载入页面
                vm.$state.reload();
            };

        }

        /**
         * 个人实时成绩（单程定距）
         * 
         * @param  {[type]} courseId   [科目]
         * @param  {[type]} sex   [性别]
         * @param  {[type]} cp    [cp点]
         * @param  {[type]} group [组别]
         * @param  {[type]} state [状态]
         * @param  {[type]} bib   [选手号]
         * @return {[type]}       [个人实时成绩（单程定距）过滤后数据]
         */
        vm.getOnewayDistData = function(courseId, sex, cp, group, state, bib) {

            // console.log({
            //     courseId: courseId,
            //     sex: sex,
            //     cp: cp,
            //     group: group,
            //     state: state,
            //     bib: bib
            // });

            var sex  = sex || '',
                cp = cp || '',
                group = group || '',
                state = state || '',
                bib = bib || '',
                search    = this.$state.params.race_id + '&course_id=' + courseId + '&search[sex]=' + sex + '&search[cp]=' + cp + '&search[group]=' + group + '&search[state]=' + state + '&search[bib]=' + bib + '&access-token=' + this.$cookieStore.get('access_token');
            console.log(search);
     
            var URL = iRunner.config.baseUrl;
            
            //模板id
            var tplId = '#person_table_oneway_dist';

            //用于存储页面上的所有选手id用于查询漏电选手
            var runnerIdList = '';

            //清空当前页面数据
            vm.realtimeData = [];

            // var token = this.$cookieStore.get('access_token');
            // console.log(URL + '/realtime/personal?race_id=' + this.$state.params.race_id + '&course_id=' + courseId + '&access-token=' + this.$cookieStore.get('access_token'));

            var tableData = angular.element(tplId).DataTable($.extend({}, vm.tableSettings.dataTable, {
                // --- Data
                // old
                // ajax: URL + '/realtime/lists?race_id=' + this.$state.params.race_id + '&course_id=' + courseId + '&genderby=all' + '&access-token=' + this.$cookieStore.get('access_token'),
                // new
                ajax: URL + '/realtime/personal?race_id=' + search,
                order: [0, "desc"], // ID 倒序
                // --- Column       
                columns: iRunner.personOnewayDistColumns,
                // --- CreatedRow
                createdRow: ( row, data, index ) => {

                    //如果有bib号搜索或者cp点为全部的情况下 无排名
                    if (bib || !cp) {
                        row.children[6].innerHTML = '-';
                        // 排名隐藏（打印）
                        data.seq = '-';
                    }
                    //保存当前页面数据
                    vm.realtimeData.push(data);

                    // console.log(row);
                    runnerIdList += ',' + data.runner_id;
                },
                // --- Callback
                initComplete: () => {
                    //添加漏点提示
                    // vm.leak();
                }
            }));

            // 点击选手号（跳转选手详情页面）
            $(tplId).on('click', 'tbody > tr a', function() {
                //存储当前搜索条件
                $rootScope.searchState = vm.searchState;
                var params = {
                    action: 'realtime',
                    name: 'dashboard.race.realtimerunner',
                    id: 'runner_id'
                }

                if (!params) return;
                console.log(params);

                var data = {},
                    that = $(this),
                    link = $(this);
                if (!link.data('runnerid')) return;
                if (link.data('course')) {
                    data['course_id'] = link.data('course')
                }    
                if (link.data('runnerid')) {    
                    data[params.id] = link.data('runnerid');
                    vm.$state.go(params.name, data);
                }
            });

            // 上下每页条数下拉框同步
            $('.dataTables_length').find('select').on('change', function(event) {
                //清空当前页面数据
                vm.realtimeData = [];
                const select =  $('.dataTables_length').find('select')

                select.val($(this).val());
            });

            $('.dataTables_paginate').on('click', "ul > li", function() {
                //保存当前页码
                vm.searchState.page = this.children[0].innerText;

                //清空当前页面数据
                vm.realtimeData = [];
            });

            //重绘表格后执行
            $(tplId).on( 'draw.dt', function () {
                //添加漏点提示
                vm.leak();
            } );

            //单程定距调漏点查询
            vm.leak = function() {
                if (vm.realtimeData.length > 0) {
                    //初始数据准备
                    $.ajax({
                        dataType:'json',
                        type: 'GET',
                        //http://local.timing.paobuqu.com/dashboard/realtime/leak?runner_ids=233404&course_id=241&access-token=
                        url: '/dashboard/realtime/leak?course_id=' + vm.course.course_id + '&runner_ids=' + runnerIdList.substring(1) + '&access-token=' + vm.$cookieStore.get('access_token'),
                        success: function(data) {
                            console.log(data);
                            //请求成功的场合
                            if (data.code == 0) {
                                $('tbody tr').each(function(index,element) {
                                    element.childNodes[7].innerHTML = data.data[$(element.childNodes[0].childNodes[0]).data('runnerid')] == 1 ? "<span style='color: #525252;'>漏点</span>" : '';
                                    console.log($(element.childNodes[0]).data('runnerid'));
                                });
                            } else {
                                vm.dialogService.error('漏点信息请求失败');
                            }
                        },
                        error: function(error) {
                            vm.dialogService.error('漏点信息请求失败');
                        }
                    });
                }
            }

            //点击置无效按钮
            $(tplId).on('click', "tbody > tr [data-action='realtime_list']", function() {
                vm.ngDialog.open({
                    template: "<p>确定要将" + $(this).data('bib') +"选手置为无效吗？<br> 点击确定按钮后，该选手所有成绩无效，实时成绩列表中不再显示该选手！</p><br><button class='btn btn-primary' ng-click='setDNF(" + $(this).data('scoreid') + ")'>确定</button>",
                    className: 'ngdialog-theme-default ngdialog-alert',
                    plain: true,
                    scope: $rootScope
                });

            });

            //置选手无效按钮点击确认
            $rootScope.setDNF = function(value) {

                //调用接口，置选手无效
                vm.ScoreService.getRealtimeupdateScore(vm.$cookieStore.get('access_token'), value + '&op=dnf')
                .then( data => {
                    // 成功调用
                    data.code==0&&vm.dialogService.success('调用成功');
                    // 调用失败, 提示用户
                    data.code!=0&&vm.dialogService.error(data.message);
                    console.log(data)
                }, error => console.log('error'));                    

                //关闭确认充值模态框
                vm.ngDialog.close();
                // 重新载入页面
                vm.$state.reload();
            };
            
        }


        vm.tableSettings = {
            KEYCODE: {
                ENTER: 13,
                DELETE: 46,
                BACKSPACE: 8,
                UP: 38,
                DOWN: 40
            },
            imageTypes: "*.gif;*.jpg;*.jpeg;*.png;",
            dataTable: {

                /*基本参数设置，以下参数设置和默认效果一致*/
                "paginate": true, //翻页功能
                "lengthChange": true, //改变每页显示数据数量
                "filter": true, //过滤功能
                "sort": true, //排序功能
                "info": true,//页脚信息
                "autoWidth": true,//自动宽度
                /*默认排序设置*/
                // "aSorting": [[ 4, "desc" ]],//设置第5个元素为默认排序
                /*默认翻页样式设置*/
                "paginationType": "full_numbers",
                /*是否开启主题*/
                // "jQueryUI": true,
                /*语言设置*/
                "language": {
                    "lengthMenu": "每页显示 _MENU_条",
                    "zeroRecords": "没有找到符合条件的数据",
                    "processing": "加载中...",
                    "info": "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
                    "infoEmpty": "没有记录",
                    // "infoFiltered": "(从 _MAX_ 条记录中过滤)",
                    "infoFiltered": "",
                    "search": "搜索：",
                    "paginate": {
                        "first": "首页",
                        "previous": "前一页",
                        "next": "后一页",
                        "last": "尾页"
                    }
                },

                // --- Data
                processing: true,
                serverSide: true,
                // --- Language
                // language: $.extend({}, iRunner.l("DATATABLE"), {
                //     processing: 'Loading...'
                // }),
                // --- Pagination
                pageLength: 50,
                pagingType: "full_numbers",
                lengthMenu: [10, 20, 50, 100, 200],
                // dom: "rt<'page-list-footer'lp>"
                dom: '<"page-list-footer"<br/>lp<"clear">irt<"page-list-footer"lp<"clear">ir'
            }
        }

    }

}

RealtimeListPersonalController.$inject = ['$rootScope', '$scope', '$cookieStore', '$timeout', '$state', '$filter', 'ngDialog', 'tableService', 'dialogService', 'ScoreService', 'getRaceDetail', 'getCourseList', 'iRunner', 'getGroupList']; 

export default RealtimeListPersonalController;